package com.zhiyou100.controller.contract;

import com.zhiyou100.dao.Impl.ContractDaoImpl;
import com.zhiyou100.emtity.Contract;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.text.SimpleDateFormat;
import java.util.Random;

/**
 * @description:
 * @author: 马跃
 * @create: 2021-01-23 14:52
 **/
@WebServlet("/contractAdd")
public class ContractAddServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        Contract contract = new Contract();
        try {
            BeanUtils.populate(contract,request.getParameterMap());

        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        contract.setC_number("R20180923"+System.currentTimeMillis()+(new Random().nextInt(10))+(new Random().nextInt(10)));
        System.out.println(contract);
        new ContractDaoImpl().add(contract);
        request.getRequestDispatcher("/contractQueryAll").forward(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
